﻿namespace ReplaceBinary
{
    using System;
    using System.Text;

    internal class Program
    {
        internal static void Main(string[] args)
        {
            if (args.Length == 4)
            {
                try
                {
                    var sourceFile = args[0];
                    var savedFile = args[1];
                    var findString = args[2];
                    var toString = args[3];
                    var toBytes = Encoding.Default.GetBytes(toString);
                    var file = PatchPro.OpenFile(sourceFile);
                    var findBytes = Encoding.Default.GetBytes(findString);
                    var result = PatchPro.ReplaceBytesInBytes(file, findBytes, toBytes);
                    PatchPro.SaveFile(savedFile, result);
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }
            else
            {
                Console.WriteLine("[sourcefile] [savedFile] [toFindString] [toReplaceString]");
            }
        }
    }
}